package asteroids;

import be.kuleuven.cs.som.annotate.*;

@Value
public final class Angle {
	/**
	 * 
	 * @param angle
	 *            The angle of this entity, expressed in Radian
	 * 
	 * @pre The angle must not be infinite nor not a number | (angle !=
	 *      Double.Nan) && (angle!= Double.POSITIVE_INFINITY) && (angle!=
	 *      Double.NEGATIVE_INFINITY)
	 * 
	 * @post The angle this entity represents equals angle modulo 2*Pi | (new
	 *       this).getAngle() == angle%(2*Math.PI)
	 * @invar The angle is valid | getAngle().isValidAngle()
	 * @invar The angle equals angle | this.getAngle() == angle
	 */
	public Angle(double angle) {

		assert isValidAngle(angle);
		this.ang = angle % (2 * Math.PI);

	}

	private final double ang;

	/**
	 * 
	 * @return The value of the angle, expressed in Radians | result == this.ang
	 */
	@Basic
	@Immutable
	public double getAngle() {
		return this.ang;
	}

	/**
	 * Checks if the angle is valid
	 * 
	 * @param angle
	 *            The angle to be checked
	 * @return true if the given angle is valid (a real number) | result ==
	 *         |(!(Double.isNaN(angle)) && (angle != Double.POSITIVE_INFINITY) &&
	 *         |(angle!= Double.NEGATIVE_INFINITY))
	 */
	public static boolean isValidAngle(double angle) {
		return (!(Double.isNaN(angle)) && (angle != Double.POSITIVE_INFINITY) && (angle != Double.NEGATIVE_INFINITY));
	}

}
